package com.hqully.smartfumehood.common.filter;

import com.hqully.smartfumehood.common.exception.JWTException;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;


/**
 * @description: 处理拦截器中抛出的异常
 * @deprecated
 *
 * @author liulingyu
 * @date 2022/5/6 20:44
 * @Version 1.0
 */
@Slf4j
public class ExceptionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (JWTException e) {
            // 异常捕获，发送到error controller
            request.setAttribute("filter.jwtError", e);
            //将异常分发到/error/exthrow控制器
            request.getRequestDispatcher("/error/jwt").forward(request, response);
        }

    }

    @Override
    public void destroy() {

    }
}
